UART_STATUS = int(0x4000)
UART_TX_DATA = int(0x4001)
UART_RX_DATA = int(0x4002)

asm_begin = \
'''(LOOP)
'''

asm_end = \
'''@LOOP
0;JMP
'''

def uart_putc(label, c):
    return \
    f'''({label})
    @{UART_STATUS}
    D=M
    @1
    D=D&A
    @{label}
    D;JGT
    @{ord(c)}
    D=A
    @{UART_TX_DATA}
    M=D
    '''
if __name__ == "__main__":
    print(asm_begin)
    hello = "Hello, world\n"
    i = 1
    label = "label"
    for c in hello:
        print(uart_putc(label + str(i), c))
        i = i + 1

    print(asm_end)
